package com.liang.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 引入依赖
 * 写配置
 * 参照文档操作
 */
@Configuration
public class ESConfig {



    /**
     * 返回操作ES的客户端
     * @return
     */
    @Bean
    public RestHighLevelClient esRestClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("8.140.106.202", 9200, "http")));
        return  client;
    }

    /**
     * 请求配置
     * RequestOptions类包含请求的一些部分，这些部分应该在同一个应用程序中的多个请求之间共享。你可以创建一个单实例，并在所有请求之间共享:
     */
    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        COMMON_OPTIONS = builder.build();
    }
}
